package dyq.example.com;


import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import java.util.ArrayList;
import java.util.List;


/**
 * A simple {@link Fragment} subclass.
 */
public class contactFragment extends Fragment {

//    define view to set the layout of fragment
    private View view;
//    define recyclerview
    private RecyclerView recyclerView;
//    define the dataset
    private List<String> list;
//    define the adpter of recyclerview
    private adapter adapter;

    public contactFragment() {
        // Required empty public constructor
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        view = inflater.inflate(R.layout.tab03, container, false);
        initData();
        initRecyclerView();
        return view;
    }

//    initialize the data
    private void initData() {
        Log.d("initdata","list");
        list = new ArrayList<String>();
        for(int i = 0;i<3;i++){
            list.add("这是第"+i+"次失败T_T");
        }
    }

//    initialize the recyclerview
    private void initRecyclerView() {
        Log.d("initrv","s");
//        get RecyclerView
        recyclerView = view.findViewById(R.id.recycleview);

////        when we know that changes in content don't change the layout size fo the RecyclerView, use this setting to avoid the same calculation to improve performance
//        recyclerView.setHasFixedSize(true);

//        create adapter for recycleview
        adapter = new adapter(getActivity(),list);

//        set adapter for recycleview
        recyclerView.setAdapter(adapter);

//        set the layoutManager to control the effect of display
        recyclerView.setLayoutManager(new LinearLayoutManager(getActivity(),LinearLayoutManager.VERTICAL,false));

//        set the cut-off rule of item
        recyclerView.addItemDecoration(new DividerItemDecoration(getActivity(),DividerItemDecoration.VERTICAL));

    }

}
